package com.college_career_system.controller;


import com.alibaba.fastjson.JSONObject;
import com.college_career_system.service.SchoolService;
import com.college_career_system.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Empty
 * @since 2022-12-06
 */
@RestController
@RequestMapping("/school")
@CrossOrigin(origins = Constant.URL, allowCredentials = "true", maxAge = 3600)
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    /**
     * 高校账号查询自己本校的就业情况
     * 可根据专业（可为null）、年份查找，年份（格式：2020）必须给
     * 若有按专业查询，需要传入专业的名字（不是id）
     * 年份和专业的标签，需要调用下面两个方法，才能获取数据库所拥有的年份和专业
     * flag=1表示找到工作的，flag=0表示未找到工作
     * @param request
     * @param profession
     * @param year
     * @return
     */
    @PostMapping("/selectUserEnrollment")
    public JSONObject selectUserEnrollment(HttpServletRequest request, String profession, String year, int flag) {
        return schoolService.selectUserEnrollment(request, profession, year, flag);
    }

    /**
     * 查询所有拥有的年份
     * @param request
     * @return
     */
    @PostMapping("/selectAllYear")
    public JSONObject selectAllYear(HttpServletRequest request) {
        return schoolService.selectAllYear(request);
    }

    /**
     * 查询所有的专业
     * @return
     */
    @PostMapping("/selectAllProfession")
    public JSONObject selectAllProfession() {
        return schoolService.selectAllProfession();
    }

    /**
     * 更新密码 传入新的密码
     * @param request
     * @param pwd
     * @return
     */
    @PostMapping("/updatePassWordById")
    @ResponseBody
    public  String updatePassWordById(HttpServletRequest request, String pwd) {
        return schoolService.updatePassWordById(request, pwd).toString();
    }
}

